<?php

namespace app\admin\controller\member;

use app\admin\model\UM as UM;
use app\admin\service\LawyerSvipService;
use ShidianUtil\Thinkphp\Response\ApiResponse;
use think\APP;
use think\exception\ValidateException;
use think\Request as Request;

/**
 * LawyerSvip 控制器
 * Class LawyerSvip
 * @package app\admin\controller\member;
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037509
 * @see \app\admin\validate\member\LawyerSvip
 */
class LawyerSvip
{
    // 请求参数
    private Request $request;

    // service
    private LawyerSvipService $service;

    public function __construct(Request $request, LawyerSvipService $lawyerSvipService)
    {
        $this->request = $request;
        $this->service = $lawyerSvipService;
    }

    /**
     * 用户管理-律师-列表
     * @param \app\admin\model\UM|null $user
     * @return ApiResponse
     * @url /member/lawyer/index
     */
    public function index(?UM $user): ApiResponse
    {
        $request = $this->request;

        $page = $request->param('page', null);
        $page_size = $request->param('page_size', null);

        return ApiResponse::success($this->service->index($user, $page, $page_size));
    }

    /**
     * 设置SVIP
     * @param UM $user
     * @return ApiResponse
     * @url /member/lawyer_svip/save
     */
    public function save(UM $user): ApiResponse
    {
        $request = $this->request;

        if (!$request->has('id')) {
            throw new ValidateException('请选择一个律师');
        }

        $this->service->modify($user, $request->param('id'), $request->param());

        return ApiResponse::success(null);
    }

}
